package com.vgemv.jsutilitysdkdemo.module.Menu.Share;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.vgemv.jsutilitysdk.geometry.JsGeometryManager;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemView.JsMenuItemView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVm;


public class ShareItemView extends JsMenuItemView {

    private RelativeLayout mrl_root;
    private ImageView miv;
    private TextView mtv_title;

    public ShareItemView(Context context) {
        super(context);
    }

    @Override
    public void customSetVm(Context context, JsMenuItemVm itemVm) {
        //1 创建rootView
        if(mrl_root == null) {
            mrl_root = new RelativeLayout(context);
            addView(mrl_root);
        }
        //2 自定义布局.
        //2 转化Vm
        ShareItemViewVm vm = (ShareItemViewVm)itemVm;

        {
            //miv
            if(miv == null) {
                miv = new ImageView(getContext());
                miv.setId(View.generateViewId());

                //layout
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ShareItemViewVm.imageSize, ShareItemViewVm.imageSize);
                lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
                lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                lp.setMargins(0, JsGeometryManager.pixelFromDp(5),0,0);
                mrl_root.addView(miv,lp);
            }

            //content
            miv.setImageResource(vm.mipmapId);
        }


        {
            if(mtv_title == null) {
                mtv_title = new TextView(getContext());
                //layout
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                lp.addRule(RelativeLayout.BELOW,miv.getId());
                lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
                lp.setMargins(0,JsGeometryManager.pixelFromDp(5),0,0);
                mrl_root.addView(mtv_title,lp);

                //content
                mtv_title.setTextSize(JsGeometryManager.pixelFromDp(3));
                mtv_title.setGravity(Gravity.CENTER);
                mtv_title.setTextAlignment(TEXT_ALIGNMENT_CENTER);
            }
            mtv_title.setText(vm.title);
        }
    }


}
